package {
	import flash.display.PixelSnapping;	
	
	import com.googlecode.milib.vo.MLEvent;	
	import com.googlecode.milib.service.singleton.MouseService;	
	
	import flash.display.Bitmap;	
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import com.googlecode.milib.MILibMain;
	import com.googlecode.milib.display.Scale9BitmapData;	
	
	/**
	 * @author Marek Brun 'minim'
	 */
	public class Scale9BitmapDataExampleMain extends MovieClip {

		private var mcSliceProvider:Scale9BitmapData;
		private var bitmap:Bitmap;
		private var ms:MouseService;

		public function Scale9BitmapDataExampleMain() {
			stage.scaleMode=StageScaleMode.NO_SCALE; 
			stage.align=StageAlign.TOP_LEFT;
			MILibMain.init(this);
			
			var mc:MovieClip=MovieClip(getChildByName('mc'));
			mcSliceProvider=Scale9BitmapData.createFromSlicedMC(mc);
			
			bitmap=new Bitmap(mcSliceProvider.getScaled9BitmapData(mc.width, mc.height), PixelSnapping.ALWAYS, true);
			addChild(bitmap);
			removeChild(mc);
			
			ms=MouseService.getInstance();
			ms.addEventListener(ms.event_Move, onMouseServiceMove);
			ms.addEventListener(ms.event_Arrive, onMouseServiceArrive);
			ms.addEventListener(ms.event_Leave, onMouseServiceLeave);
			stage.frameRate=0.01;
		}//<>
		
//********************************************************************************************
//		events for Scale9BitmapDataExampleMain
//********************************************************************************************
		protected function onMouseServiceMove(event:MLEvent):void {
			stage.frameRate=60;
			bitmap.bitmapData.dispose();
			bitmap.bitmapData=mcSliceProvider.getScaled9BitmapData(mouseX, mouseY);
		}//<<
		
		protected function onMouseServiceArrive(event:MLEvent):void {
			stage.frameRate=60;
		}
		
		protected function onMouseServiceLeave(event:MLEvent):void {
			stage.frameRate=0.01;
		}
		
	}
}
